package 将数组和减半的最少操作次数;

import java.util.PriorityQueue;

class Solution {
    public int halveArray(int[] nums) {
        PriorityQueue<Double> q = new PriorityQueue<>((a, b) -> {
            return b.compareTo(a);
        });
        int ret = 0, n = nums.length;
        double sum = 0;
        for (int i = 0; i < n; i++) {
            sum += nums[i];
            q.offer((double)nums[i]);
        }
        sum /= 2;
        while (sum > 0) {
            double t = q.poll() / 2;
            sum -= t;
            q.offer(t);
            ret++;
        }
        return ret;
    }
}